import axios, { HttpResponse } from '@/api/interceptor';
import { RoleData } from '@/api/role/types';

export const getRoleList = async (): Promise<HttpResponse<RoleData[]>> => {
  const result = await axios.get<HttpResponse<RoleData[]>>('/role/getRoleList');
  return result.data;
};

export const selectPageRole = async (params: any) => {
  const result = await axios({
    url: '/role/listPage',
    method: 'GET',
    params,
  });
  return result.data;
};

export const editRole = async (roleData: RoleData) => {
  const result = await axios({
    url: '/role/editRole',
    method: 'PUT',
    data: roleData,
  });
  return result.data;
};

export const createRole = async (roleData: RoleData) => {
  const result = await axios({
    url: '/role/createRole',
    method: 'POST',
    data: roleData,
  });
  return result.data;
};

export const getRoleDetail = async (id: number) => {
  const result = await axios({
    url: '/role/getRoleDetail',
    method: 'GET',
    params: { id },
  });
  return result.data;
};

export const deleteRoleById = async (id: number) => {
  const result = await axios({
    url: '/role/removeRole',
    method: 'DELETE',
    params: { id },
  });
  return result.data;
};
